//
//  BIZOfflineConsultRecordsCell.m
//  biz
//
//  Created by zhangfuwei on 2017/4/17.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZOfflineConsultRecordsCell.h"
#import "BIZOfflineConsultRecordsModel.h"

//  视图间距
static CGFloat kMargin      =10;
static CGFloat kViewMargin  = 15;



@implementation BIZOfflineConsultRecordsCell{
    UIView      *_redPoint;// 红点提醒
    UIView      *_subViewsSuperView;
    UIImageView *_headImageView; // 头像
    UILabel *_nameLabel; // 姓名
    UILabel *_companyLabel;//  公司
    UILabel *_positionLabel; // 职位
    UILabel *_contentLabel; // 内容
    UILabel *_timeLabel; // 时间
    UILabel *_stateLabel; // 接单状态
    
    UIView  *_splitLine; // 分割线
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = HEXCOLOR(0xf9f9f9);

        [self loadCustomizedSubviews];
    }
    return self;
}


- (void)loadCustomizedSubviews {
    
    //  子控件的父视图
    _subViewsSuperView = [[UIView alloc] init];
    _subViewsSuperView.backgroundColor = [UIColor whiteColor];
    
    //  灰色边框
    [_subViewsSuperView.layer setBorderColor:HEXCOLOR(0xeeedee).CGColor];
    [_subViewsSuperView.layer setBorderWidth:1];
    
    [self.contentView addSubview:_subViewsSuperView];

    [_subViewsSuperView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-1*kMargin);
    }];
    
    _headImageView = [[UIImageView alloc] init];
    _headImageView.layer.cornerRadius = 5;
    _headImageView.clipsToBounds = YES;
    
    _redPoint       = [[UIView alloc] init];
    _redPoint.backgroundColor = [UIColor redColor];
    _redPoint.layer.cornerRadius = 5;
    _redPoint.clipsToBounds = YES;
    _redPoint.hidden = YES;
    
    _nameLabel      = [[UILabel alloc] init];
    _positionLabel  = [[UILabel alloc] init];
    _companyLabel   = [[UILabel alloc] init];
    _timeLabel      = [[UILabel alloc] init];
    _stateLabel     = [[UILabel alloc] init];
    _contentLabel   = [[UILabel alloc] init];
    
    _positionLabel.textAlignment    = NSTextAlignmentLeft;
    _timeLabel.textAlignment        = NSTextAlignmentLeft;
    _stateLabel.textAlignment       = NSTextAlignmentRight;
    
    _contentLabel.numberOfLines     = 0;
    
    
    _nameLabel.font     = CHINESE_SYSTEM(15);
    _positionLabel.font = CHINESE_SYSTEM(12);
    _companyLabel.font  = CHINESE_SYSTEM(12);
    _contentLabel.font  = CHINESE_SYSTEM(14);
    _timeLabel.font     = CHINESE_SYSTEM(12);
    _stateLabel.font    = CHINESE_SYSTEM(13);
    
    
    _nameLabel.textColor        = HEXCOLOR(0x4c5c6c);
    _positionLabel.textColor    = HEXCOLOR(0x010101);
    _companyLabel.textColor     = HEXCOLOR(0x666666);
    _contentLabel.textColor     = HEXCOLOR(0x333333);
    _timeLabel.textColor        = HEXCOLOR(0xb7b7b7);
    
    _splitLine = [[UIView alloc] init];
    _splitLine.backgroundColor = HEXCOLOR(0xeeedee);
    
    [_subViewsSuperView addSubview:_headImageView];
    [_subViewsSuperView insertSubview:_redPoint aboveSubview:_headImageView];
    
    [_subViewsSuperView addSubview:_nameLabel];
    [_subViewsSuperView addSubview:_positionLabel];
    [_subViewsSuperView addSubview:_companyLabel];
    [_subViewsSuperView addSubview:_contentLabel];
    [_subViewsSuperView addSubview:_timeLabel];
    [_subViewsSuperView addSubview:_stateLabel];
    
    [_subViewsSuperView addSubview:_splitLine];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    _headImageView.frame = CGRectMake(kViewMargin, kMargin, 50, 50);
    _redPoint.frame = CGRectMake(kViewMargin+45, kMargin, 5, 5);
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headImageView.mas_right).offset(kViewMargin);
        make.top.equalTo(_headImageView);
        make.height.equalTo(@(15));
    }];
    
    [_positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_nameLabel);
        make.left.equalTo(_nameLabel.mas_right).offset(kMargin);
        make.height.equalTo(@12);
    }];
    
    
    [_companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@12);
        make.left.equalTo(_nameLabel);
        make.top.equalTo(_nameLabel.mas_bottom).offset(kViewMargin);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headImageView.mas_left);
        make.top.equalTo(_companyLabel.mas_bottom).offset(17);
        make.right.equalTo(_subViewsSuperView).offset(-1*kViewMargin);
        
    }];
    
    [_splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_subViewsSuperView).offset(kViewMargin);
        make.right.equalTo(_subViewsSuperView).offset(-1*kViewMargin);
        make.top.equalTo(_contentLabel.mas_bottom).offset(1*kViewMargin);
        make.height.equalTo(@0.5);
    }];
    
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_splitLine);
        make.top.equalTo(_splitLine.mas_bottom).offset(13);
        make.height.equalTo(@12);
        make.bottom.equalTo(_subViewsSuperView).offset(-1*13);
    }];
    
    [_stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_subViewsSuperView).offset(-1*kViewMargin);
        make.centerY.equalTo(_timeLabel);
        make.height.equalTo(@13);
    }];
    
}


- (void)setDataModel:(BIZOfflineConsultRecordsDataModel *)dataModel {
    _dataModel = dataModel;
    NSString    *state ;
    UIColor     *stateColor;
    switch (dataModel.status.intValue) {
        case 0:
            state = @"咨询师未接单";
            stateColor = HEXCOLOR(0xfb6a31);
            break;
        case 1:
            state = @"咨询师已接单";
            stateColor = HEXCOLOR(0x00c44e);

            break;
        case 2:
            state = @"咨询师拒单";
            stateColor = HEXCOLOR(0x2079ef);

            break;
        case 3:
            state = @"服务完成";
            stateColor = HEXCOLOR(0xffa200);
            break;
        case 4:
            state = @"服务无响应";
            stateColor = HEXCOLOR(0xcc100f);
            break;
        default:
            break;
    }
    
    _stateLabel.text        = state;
    _stateLabel.textColor   = stateColor;
    [SDWebImageTool imageView:_headImageView imageName:dataModel.headImg placeHolder:@"default-head" showProgress:NO];
    _nameLabel.text         = dataModel.cname;
    _positionLabel.text     = dataModel.position;
    _companyLabel.text      = dataModel.fname;
    _contentLabel.text      = dataModel.content;
    _timeLabel.text         = [NSDate stringFromTimestamp:dataModel.updateTime dateFormat:@"yyyy-MM-dd hh:mm"];
    _redPoint.hidden = !dataModel.redType.intValue;
    [self layoutIfNeeded];
}

@end
